#ifndef IAP_MERGE_DIALOG_H
#define IAP_MERGE_DIALOG_H

#include <QDialog>
#include <QStandardItemModel>
#include <QMessageBox>
#include <QStandardItemModel>
#include <QHeaderView>
#include <QFileDialog>
#include <QProcess>
#include "inputaddressdialog.h"

#define FLASH_ADDRESS_BEGIN 0x08000000
#define FLASH_ADDRESS_END 0x080A00000

struct endpoint
{
    QString filename;
    QString filepath;
    uint32_t flashBeginAddress;
    uint32_t flashEndAddress;
    uint32_t crc;
    QByteArray data;
};

QT_BEGIN_NAMESPACE
namespace Ui { class IAPMergeDialog; }
QT_END_NAMESPACE

class IAPMergeDialog : public QDialog
{
    Q_OBJECT

public:
    IAPMergeDialog(QWidget *parent = nullptr);
    ~IAPMergeDialog();
    static unsigned int CRC32(const void *buf, unsigned int len);

private:
    Ui::IAPMergeDialog *ui;
    QStandardItemModel* model = nullptr;
    QList<endpoint> fileList;
    QString lastSavePath;
    void msgBoxError(QString text);
    void msgBoxInfo(QString text);
    void msgBoxWarn(QString text);
    void initTableHeader();

private slots:
    void addFile();
    void delFile();
    void generateFile();
};
#endif // IAP_MERGE_DIALOG_H
